package com.szy.douyou_comment.web;


import com.szy.douyou_comment.config.ResultDTO;
import com.szy.douyou_comment.dao.Comment;
import com.szy.douyou_comment.dao.CommentReq;
import com.szy.douyou_comment.service.CommentService;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author sunziyan
 * @date 2022/4/21
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private CommentService commentService;

    /**
     * 分页查询该文章下所有评论
     * @param articleId
     * @return
     */
    @GetMapping("/queryAllByArticle/{articleId}")
    public ResultDTO queryAllByArticle(@PathVariable("articleId") Long articleId){

        return commentService.getCommentByArticleId(articleId);
    }

    /**
     * 添加一条评论
     * @param comment
     * @return
     */
    @PostMapping("/addOne")
    public ResultDTO addOne(@RequestBody Comment comment){
        System.out.println(comment);
        return commentService.addOneComment(comment);
    }

    /**
     * 分页查询所有评论
     * @param commentReq
     * @return
     */
    @PostMapping("/queryAll")
    public ResultDTO queryAll(@RequestBody CommentReq commentReq){
        return commentService.getAllComment(commentReq);
    }

    /**
     * 删除一条评论
     * @param commentId
     * @return
     */
    @GetMapping("/deleteOne/{commentId}")
    public ResultDTO deleteOne(@PathVariable("commentId")Long commentId){
        return commentService.deleteCommentByCommentId(commentId);
    }
}
